## Replication code for "Mayoral Partisanship and Municipal Fiscal Policy"
## Chris Warshaw and Justin de Benedictis-Kessner
### Put all files into the same working directory

## function to convert rd.robust tables:
source("rd.export.R")
load(file="mayors_rdd_analysis_final.RData")
library(foreign)
library(plyr); library(dplyr)
library(coin)
library(rdrobust)
library(rms)
library(rdd)
library(ggplot2)
library(reshape2)
library(xtable)

##################
### RDD analysis of major outcomes for size of government
##################

cct.expenditures <- with(data2, rdrobust(y=Total.Expenditure.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))


width <- .005
data2 <- mutate(data2, bin=cut(demshare, breaks=seq(-.5, .5, width)))
bin2.df <- data.frame(bin.mean=tapply(data2$Total.Expenditure.D2,
                         data2$bin, mean, na.rm=TRUE),
                     mid=seq(-.5 + width/2, .5 - width/2, width),
                     n=tapply(data2$Total.Expenditure.D2, data2$bin,
                         length))

tri <- function (x, h, c=0) pmax(0, 1 - abs((x - c) / h))


pdf("expendituresRD.pdf", width=8, height=6)
(ggplot(data2)
 + geom_point(aes(x = demshare, y = Total.Expenditure.D2), alpha=.1)
 + geom_smooth(data=subset(data2, demshare > 0),
               aes(x = demshare, y = Total.Expenditure.D2,
                   weight=tri(demshare, cct.expenditures$h)),
               method = 'lm', formula = y ~ poly(x, 1), size=1.5)
 + geom_smooth(data=subset(data2, demshare < 0),
               aes(x = demshare, y = Total.Expenditure.D2,
                   weight=tri(demshare, cct.expenditures$h)),
               method = 'lm', formula = y ~ poly(x, 1), size=1.5)
 + geom_point(data=bin2.df, aes(x=mid, y=bin.mean, size=n), pch=1)
 + geom_vline(xintercept=0)
 + geom_hline(yintercept=0, lty='dotted')
 + coord_cartesian(ylim = c(-1000, 1000))
 + scale_x_continuous(breaks=seq(-.5, .5, .05),
                      limits=c(-cct.expenditures$h,
                          cct.expenditures$h))
 
 + labs(size = '# Obs. in\n2-unit Bin')
 + theme_bw()
 + labs(x = "Democrats' Vote Share",
        y = "Change in Per Capita Expenditures")
 + ggtitle("Second Year after Mayoral Election")
 + annotate('text', x = .02, y = -150, 0.05, hjust=0, parse=TRUE,
            label = paste('hat(tau)==',
                round(cct.expenditures$coef['Conventional', ], 1),
                '~(list(', round(cct.expenditures$ci['Robust', 1], 1),
                ',', round(cct.expenditures$ci['Robust', 2], 1),
                '))'))
 
 )
dev.off()

cct.expenditures.general <- with(data2, rdrobust(y=General.Expenditure.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.expenditures.log <- with(data2, rdrobust(y=Total.Expenditure.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.taxes <- with(data2, rdrobust(y=Total.Taxes.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.taxes.log <- with(data2, rdrobust(y=Total.Taxes.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.revenue <- with(data2, rdrobust(y=revenue.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))



#### #### #### #### 
#### Sources of Revenue
#### #### #### #### 

cct.debt <- with(data2, rdrobust(y=debt.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))


width <- .005
data2 <- mutate(data2, bin=cut(demshare, breaks=seq(-.5, .5, width)))
bin2.df <- data.frame(bin.mean=tapply(data2$debt.PC.D2,
                         data2$bin, mean, na.rm=TRUE),
                     mid=seq(-.5 + width/2, .5 - width/2, width),
                     n=tapply(data2$debt.PC.D2, data2$bin, length))
tri <- function (x, h, c=0) pmax(0, 1 - abs((x - c) / h))


pdf("debtRD.pdf", width=8, height=6)
(ggplot(data2)
 + geom_point(aes(x = demshare, y = debt.PC.D2), alpha=.1)
 + geom_smooth(data=subset(data2, demshare > 0),
               aes(x = demshare, y = debt.PC.D2,
                   weight=tri(demshare, cct.debt$h)),
               method = 'lm', formula = y ~ poly(x, 1), size=1.5)
 + geom_smooth(data=subset(data2, demshare < 0),
               aes(x = demshare, y = debt.PC.D2,
                   weight=tri(demshare, cct.debt$h)),
               method = 'lm', formula = y ~ poly(x, 1), size=1.5)
 + geom_point(data=bin2.df, aes(x=mid, y=bin.mean, size=n), pch=1)
 + geom_vline(xintercept=0)
 + geom_hline(yintercept=0, lty='dotted')
 + coord_cartesian(ylim = c(-1000, 1000))
 + scale_x_continuous(breaks=seq(-.5, .5, .05), limits=c(-cct.debt$h, cct.debt$h))
 + labs(size = '# Obs. in\n2-unit Bin')
 + theme_bw()
 + labs(x = "Democrats' Vote Share",
        y = "Change in Per Capita Debt")
 + ggtitle("Second Year after Mayoral Election")
 + annotate('text', x = .02, y = -150, 0.05, hjust=0, parse=TRUE,
            label = paste('hat(tau)==', round(cct.debt$coef['Conventional', ], 1),
                '~(list(', round(cct.debt$ci['Robust', 1], 1),
                ',', round(cct.debt$ci['Robust', 2], 1), '))'))
 )
dev.off()
  
cct.LT.debt.ffc <- with(data2, rdrobust(y=LT.debt.ffc.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))


cct.LT.debt.ng <- with(data2, rdrobust(y=LT.debt.ng.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.LT.debt <- with(data2, rdrobust(y=LT.debt.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))


cct.charges <- with(data2, rdrobust(y=charges.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.propertytaxPC <- with(data2, rdrobust(y=propertytax.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.salestaxPC <- with(data2, rdrobust(y=salestax.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.salestax.select.PC <- with(data2, rdrobust(y=salestax.select.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.salestax.general.PC <- with(data2, rdrobust(y=salestax.general.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.revenueown <- with(data2, rdrobust(y=revenueown.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.revenueig <- with(data2, rdrobust(y=revenueig.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.revenuegeneral <- with(data2, rdrobust(y=revenuegeneral.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.revenueowngeneral <- with(data2, rdrobust(y=revenueowngeneral.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.utilityrev <- with(data2, rdrobust(y=utilitiesrev.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.salestax.perc <- with(data2, rdrobust(y=salestax_perc.D2 , x=demshare ,
                                      bwselect="CCT", all=TRUE, kernel='uni'))

cct.propertytax.perc <- with(data2, rdrobust(y=propertytax_perc.D2 , x=demshare ,
                                      bwselect="CCT", all=TRUE, kernel='uni'))

#### #### #### #### 
#### Sources of Revenue
#### #### #### #### 

cct.debt <- with(data2, rdrobust(y=debt.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

width <- .005
data2 <- mutate(data2, bin=cut(demshare, breaks=seq(-.5, .5, width)))
bin2.df <- data.frame(bin.mean=tapply(data2$debt.PC.D2,
                         data2$bin, mean, na.rm=TRUE),
                     mid=seq(-.5 + width/2, .5 - width/2, width),
                     n=tapply(data2$debt.PC.D2, data2$bin, length))
tri <- function (x, h, c=0) pmax(0, 1 - abs((x - c) / h))


pdf("debtRD.pdf", width=8, height=6)
(ggplot(data2)
 + geom_point(aes(x = demshare, y = debt.PC.D2), alpha=.1)
 + geom_smooth(data=subset(data2, demshare > 0),
               aes(x = demshare, y = debt.PC.D2,
                   weight=tri(demshare, cct.debt$h)),
               method = 'lm', formula = y ~ poly(x, 1), size=1.5)
 + geom_smooth(data=subset(data2, demshare < 0),
               aes(x = demshare, y = debt.PC.D2,
                   weight=tri(demshare, cct.debt$h)),
               method = 'lm', formula = y ~ poly(x, 1), size=1.5)
 + geom_point(data=bin2.df, aes(x=mid, y=bin.mean, size=n), pch=1)
 + geom_vline(xintercept=0)
 + geom_hline(yintercept=0, lty='dotted')
 + coord_cartesian(ylim = c(-1000, 1000))
 + scale_x_continuous(breaks=seq(-.5, .5, .05), limits=c(-cct.debt$h, cct.debt$h))
 + labs(size = '# Obs. in\n2-unit Bin')
 + theme_bw()
 + labs(x = "Democrats' Vote Share",
        y = "Change in Per Capita Debt")
 + ggtitle("Second Year after Mayoral Election")
 + annotate('text', x = .02, y = -150, 0.05, hjust=0, parse=TRUE,
            label = paste('hat(tau)==', round(cct.debt$coef['Conventional', ], 1),
                '~(list(', round(cct.debt$ci['Robust', 1], 1),
                ',', round(cct.debt$ci['Robust', 2], 1), '))'))
 )
dev.off()

cct.debt.ffc <- with(data2, rdrobust(y=debt.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.debt.ng <- with(data2, rdrobust(y=charges.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.debt.lt <- with(data2, rdrobust(y=charges.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.charges <- with(data2, rdrobust(y=charges.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.propertytaxPC <- with(data2, rdrobust(y=propertytax.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.salestaxPC <- with(data2, rdrobust(y=salestax.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.salestax.select.PC <- with(data2, rdrobust(y=salestax.select.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.salestax.general.PC <- with(data2, rdrobust(y=salestax.general.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.revenueown <- with(data2, rdrobust(y=revenueown.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.revenueig <- with(data2, rdrobust(y=revenueig.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.revenuegeneral <- with(data2, rdrobust(y=revenuegeneral.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.revenueowngeneral <- with(data2, rdrobust(y=revenueowngeneral.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.utilityrev <- with(data2, rdrobust(y=utilitiesrev.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.salestax.perc <- with(data2, rdrobust(y=salestax_perc.D2 , x=demshare ,
                                      bwselect="CCT", all=TRUE, kernel='uni'))

cct.propertytax.perc <- with(data2, rdrobust(y=propertytax_perc.D2 , x=demshare ,
                                      bwselect="CCT", all=TRUE, kernel='uni'))

#### #### #### #### 
#### Sources of Revenue, log
#### #### #### #### 

cct.revenue.log <- with(data2, rdrobust(y=revenue.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.debt.log <- with(data2, rdrobust(y=debt.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.charges.log <- with(data2, rdrobust(y=charges.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.propertytaxPC.log <- with(data2, rdrobust(y=propertytax.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.salestaxPC.log <- with(data2, rdrobust(y=salestax.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.salestax.select.PC.log <- with(data2, rdrobust(y=salestax.select.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.salestax.general.PC.log <- with(data2, rdrobust(y=salestax.general.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.revenueown.log <- with(data2, rdrobust(y=revenueown.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.revenueig.log <- with(data2, rdrobust(y=revenueig.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.revenuegeneral.log <- with(data2, rdrobust(y=revenuegeneral.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.revenueowngeneral.log <- with(data2, rdrobust(y=revenueowngeneral.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))


#### #### #### #### #### 
## Types of Expenditures
#### #### #### #### #### 

cct.education <- with(data2, rdrobust(y=education.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.fire <- with(data2, rdrobust(y=fire.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.police <- with(data2, rdrobust(y=police.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.health <- with(data2, rdrobust(y=health.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.highways <- with(data2, rdrobust(y=highways.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.housing <- with(data2, rdrobust(y=housing.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.libraries <- with(data2, rdrobust(y=libraries.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.parks <- with(data2, rdrobust(y=parks.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.sanitation <- with(data2, rdrobust(y=sanitation.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.utilities <- with(data2, rdrobust(y=utilities.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.welfare <- with(data2, rdrobust(y=welfare.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.interest <- with(data2, rdrobust(y=interest.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.admin <- with(data2, rdrobust(y=admin.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.salaries <- with(data2, rdrobust(y=salaries.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

#### #### #### #### #### 
## Types of Expenditures, log
#### #### #### #### #### 

cct.expenditures.general.log <- with(data2, rdrobust(y=General.Expenditure.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.education.log <- with(data2, rdrobust(y=education.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.fire.log <- with(data2, rdrobust(y=fire.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.police.log <- with(data2, rdrobust(y=police.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.health.log <- with(data2, rdrobust(y=health.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.highways.log <- with(data2, rdrobust(y=highways.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.housing.log <- with(data2, rdrobust(y=housing.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.libraries.log <- with(data2, rdrobust(y=libraries.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.parks.log <- with(data2, rdrobust(y=parks.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.sanitation.log <- with(data2, rdrobust(y=sanitation.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.utilities.log <- with(data2, rdrobust(y=utilities.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.welfare.log <- with(data2, rdrobust(y=welfare.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.interest.log <- with(data2, rdrobust(y=interest.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.admin.log <- with(data2, rdrobust(y=admin.PC.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))


#################
### Placebo tests
#################

cct.mayor_lagged2 <- with(data2, rdrobust(y=current_mayor_placebocheck.lag2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.mayor_lagged4 <- with(data2, rdrobust(y=current_mayor_placebocheck.lag4 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.demshare_lagged2 <- with(data2, rdrobust(y=demshare.Dlag2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.demshare_lagged4 <- with(data2, rdrobust(y=demshare.Dlag4 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.exp_delta2_lagged <- with(data2, rdrobust(y=Total.Expenditure.PC , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.exp_delta2_lagged2 <- with(data2, rdrobust(y=Total.Expenditure.D2.lagged , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

                                   
#### #### #### #### #### 
## Institutions Analysis
#### #### #### #### #### 

## By Partisan elections

cct.expenditures_p <- with(data2[data2$icma_partisan==1,],
                           rdrobust(y=Total.Expenditure.D2 ,
                                    x=demshare ,
                                    bwselect="CCT", all=TRUE, kernel='uni'))
cct.expenditures_np <- with(data2[data2$icma_partisan==0,],
                            rdrobust(y=Total.Expenditure.D2 ,
                                     x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))


## Form of Government
cct.expenditures_manager <- with(data2[data2$icma_fog==2,],
                                 rdrobust(y=Total.Expenditure.D2 ,
                                          x=demshare ,
                                    bwselect="CCT", all=TRUE, kernel='uni'))
cct.expenditures_nomanager <- with(data2[data2$icma_fog==1,],
                                   rdrobust(y=Total.Expenditure.D2 ,
                                            x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

#### #### #### #### #### 
## Robustness Checks for findings on Expenditures
#### #### #### #### #### 

cct.expenditures1 <- with(data2[data2$YearData<1972,],
                          rdrobust(y=Total.Expenditure.D2 ,
                                   x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.expenditures2 <- with(data2[data2$YearData>1971 &
                                    data2$YearData<1992,],
                          rdrobust(y=Total.Expenditure.D2 ,
                                   x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.expenditures3 <- with(data2[data2$YearData>1991,],
                          rdrobust(y=Total.Expenditure.D2 ,
                                   x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
                                     
cct.expenditures.general1 <- with(data2[data2$YearData<1972,],
                                  rdrobust(y=General.Expenditure.D2 ,
                                           x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.expenditures.general2 <- with(data2[data2$YearData>1971 &
                                            data2$YearData<1992,],
                                  rdrobust(y=General.Expenditure.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.expenditures.general3 <- with(data2[data2$YearData>1991,],
                                  rdrobust(y=General.Expenditure.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))


cct.expenditures.log1 <- with(data2[data2$YearData<1972,],
                              rdrobust(y=Total.Expenditure.D2.log ,
                                       x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.expenditures.log2 <- with(data2[data2$YearData>1971 &
                                        data2$YearData<1992,],
                              rdrobust(y=Total.Expenditure.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.expenditures.log3 <- with(data2[data2$YearData>1991,],
                              rdrobust(y=Total.Expenditure.D2.log ,
                                       x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.taxes1 <- with(data2[data2$YearData<1972,], rdrobust(y=Total.Taxes.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.taxes2 <- with(data2[data2$YearData>1971 & data2$YearData<1992,],
                   rdrobust(y=Total.Taxes.D2 ,
                            x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.taxes3 <- with(data2[data2$YearData>1982,], rdrobust(y=Total.Taxes.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.taxes.log1 <- with(data2[data2$YearData<1972,], rdrobust(y=Total.Taxes.D2.log, x=demshare,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.taxes.log2 <- with(data2[data2$YearData>1971 &
                                 data2$YearData<1992,],
                       rdrobust(y=Total.Taxes.D2.log ,
                                x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.taxes.log3 <- with(data2[data2$YearData>1991,],
                       rdrobust(y=Total.Taxes.D2.log ,
                                x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.revenue1 <- with(data2[data2$YearData<1972,],
                     rdrobust(y=revenue.PC.D2 ,
                              x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.revenue2 <- with(data2[data2$YearData>1971 &
                               data2$YearData<1992,],
                     rdrobust(y=revenue.PC.D2 ,
                              x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.revenue3 <- with(data2[data2$YearData>1991,],
                     rdrobust(y=revenue.PC.D2 ,
                              x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.debt1 <- with(data2[data2$YearData<1972,], rdrobust(y=debt.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.debt2 <- with(data2[data2$YearData>1971 & data2$YearData<1992,],
                  rdrobust(y=debt.PC.D2 ,
                           x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.debt3 <- with(data2[data2$YearData>1991,], rdrobust(y=debt.PC.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))


##################
## Robustness checks against other datasets
##################

(cct.expenditures.fg <- with(data2, rdrobust(y=Total.Expenditure.D2 , x=demshare_fg ,
                                     bwselect="CCT", all=TRUE, kernel='uni')))
                                     
(cct.expenditures.gh <- with(data2, rdrobust(y=Total.Expenditure.D2 , x=demshare_gh ,
                                     bwselect="CCT", all=TRUE, kernel='uni')))
                                     
 (cct.expenditures.oc <- with(data2, rdrobust(y=Total.Expenditure.D2 , x=demshare_oc ,
                                     bwselect="CCT", all=TRUE, kernel='uni')))

 (cct.expenditures.large <- with(data2[data2$population_est>170000,],
                                 rdrobust(y=Total.Expenditure.D2 ,
                                          x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni')))

 (cct.expenditures.medium <- with(data2[data2$population_est<170000,],
                                  rdrobust(y=Total.Expenditure.D2 ,
                                           x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni')))


## By Time leads
cct.expenditures.t1 <- with(data2[data2$YearData<2006,],
                            rdrobust(y=Total.Expenditure.D1 ,
                                     x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.expenditures.t2 <- with(data2[data2$YearData<2006,],
                            rdrobust(y=Total.Expenditure.D2 ,
                                     x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.expenditures.t3 <- with(data2[data2$YearData<2006,],
                            rdrobust(y=Total.Expenditure.D3 ,
                                     x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.expenditures.t4 <- with(data2[data2$YearData<2006,],
                            rdrobust(y=Total.Expenditure.D4 ,
                                     x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.expenditures.t5 <- with(data2[data2$YearData<2006,],
                            rdrobust(y=Total.Expenditure.D5 ,
                                     x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.expenditures.t6 <- with(data2[data2$YearData<2006,],
                            rdrobust(y=Total.Expenditure.D6 ,
                                     x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.expenditures.t7 <- with(data2[data2$YearData<2006,],
                            rdrobust(y=Total.Expenditure.D7 ,
                                     x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.expenditures.t8 <- with(data2[data2$YearData<2006,],
                            rdrobust(y=Total.Expenditure.D8 ,
                                     x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

## By Time leads
cct.debt.t1 <- with(data2[data2$YearData<2006,],
                            rdrobust(y=debt.PC.D1 ,
                                     x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.debt.t2 <- with(data2[data2$YearData<2006,],
                            rdrobust(y=debt.PC.D2 ,
                                     x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.debt.t3 <- with(data2[data2$YearData<2006,],
                            rdrobust(y=debt.PC.D3 ,
                                     x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.debt.t4 <- with(data2[data2$YearData<2006,],
                            rdrobust(y=debt.PC.D4 ,
                                     x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.debt.t5 <- with(data2[data2$YearData<2006,],
                            rdrobust(y=debt.PC.D5 ,
                                     x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.debt.t6 <- with(data2[data2$YearData<2006,],
                            rdrobust(y=debt.PC.D6 ,
                                     x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))



## By Region
cct.expenditures.south<-with(data2[data2$REGION4=="South",], rdrobust(y=Total.Expenditure.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))
cct.expenditures.nonsouth<-with(data2[data2$REGION4!="South",], rdrobust(y=Total.Expenditure.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

rd<-matrix(nrow=6, ncol=4, data=NA)
rd[,1] <- c(1,2,3,4,5,6)
rd[,2] <- as.numeric(cbind(cct.expenditures.t1$tabl3.str[1,1],
                           cct.expenditures.t2$tabl3.str[1,1],
                           cct.expenditures.t3$tabl3.str[1,1],
                           cct.expenditures.t4$tabl3.str[1,1],
                           cct.expenditures.t5$tabl3.str[1,1],
                           cct.expenditures.t6$tabl3.str[1,1]))

rd[,3] <- as.numeric(cbind(cct.expenditures.t1$tabl3.str[3,5],
                           cct.expenditures.t2$tabl3.str[3,5],
                           cct.expenditures.t3$tabl3.str[3,5],
                           cct.expenditures.t4$tabl3.str[3,5],
                           cct.expenditures.t5$tabl3.str[3,5],
                           cct.expenditures.t6$tabl3.str[3,5]))

rd[,4] <-
    as.numeric(cbind(cct.expenditures.t1$tabl3.str[3,6]
                    ,cct.expenditures.t2$tabl3.str[3,6],
                     cct.expenditures.t3$tabl3.str[3,6],
                     cct.expenditures.t4$tabl3.str[3,6],
                     cct.expenditures.t5$tabl3.str[3,6],
                     cct.expenditures.t6$tabl3.str[3,6]))
colnames(rd)<-c("lead","est", "ci_lower", "ci_upper")
rd<-as.data.frame(rd)
pdf("expendituresRD_leads.pdf", width=10, height=4)
(ggplot(subset(rd))
 + geom_pointrange(aes(x = lead, y = est, ymin = `ci_lower`,
                       ymax = `ci_upper`))
 + geom_hline(yintercept = 0, linetype = 'dotted')
 + ylab('Effect on Per Capita Expenditures\n(Robust 95% CI)')
 + xlab("Years after Election")
 + theme_bw()
 )
dev.off()

## debt
rd<-matrix(nrow=6, ncol=4, data=NA)
rd[,1] <- c(1,2,3,4,5,6)
rd[,2] <- as.numeric(cbind(cct.debt.t1$tabl3.str[1,1],
                           cct.debt.t2$tabl3.str[1,1],
                           cct.debt.t3$tabl3.str[1,1],
                           cct.debt.t4$tabl3.str[1,1],
                           cct.debt.t5$tabl3.str[1,1],
                           cct.debt.t6$tabl3.str[1,1]))

rd[,3] <- as.numeric(cbind(cct.debt.t1$tabl3.str[3,5],
                           cct.debt.t2$tabl3.str[3,5],
                           cct.debt.t3$tabl3.str[3,5],
                           cct.debt.t4$tabl3.str[3,5],
                           cct.debt.t5$tabl3.str[3,5],
                           cct.debt.t6$tabl3.str[3,5]))

rd[,4] <-
    as.numeric(cbind(cct.debt.t1$tabl3.str[3,6]
                    ,cct.debt.t2$tabl3.str[3,6],
                     cct.debt.t3$tabl3.str[3,6],
                     cct.debt.t4$tabl3.str[3,6],
                     cct.debt.t5$tabl3.str[3,6],
                     cct.debt.t6$tabl3.str[3,6]))
colnames(rd)<-c("lead","est", "ci_lower", "ci_upper")
rd<-as.data.frame(rd)
pdf("debtRD_leads.pdf", width=10, height=4)
(ggplot(subset(rd))
 + geom_pointrange(aes(x = lead, y = est, ymin = `ci_lower`,
                       ymax = `ci_upper`))
 + geom_hline(yintercept = 0, linetype = 'dotted')
 + ylab('Effect on Per Capita Debt\n(Robust 95% CI)')
 + xlab("Years after Election")
 + theme_bw()
 )
dev.off()
##################
## Descriptive summaries
##################                                                                               
summary(data2$Total.Expenditure.PC)
summary(data2$General.Expenditure.PC)
#summary(data.use$Total.Expenditure.PC[data.use$mayor_party_current=="D" & data.use$population_est>75000])
#summary(data.use$Total.Expenditure.PC[data.use$mayor_party_current=="R"& data.use$population_est>75000])
summary(data2$fire.PC)
summary(data2$police.PC)
summary(data2$health.PC)
summary(data2$highways.PC)
summary(data2$housing.PC)
summary(data2$libraries.PC)
summary(data2$parks.PC)
summary(data2$sanitation.PC)
summary(data2$utilities.PC)
summary(data2$welfare.PC)
summary(data2$interest.PC)
summary(data2$admin.PC)
summary(data2$education.PC)

summary(data2$Total.Taxes.PC)
summary(data2$salestax.PC)
summary(data2$debt.PC)


##################
##TABLE WITH MAIN RESULTS
##################

##################
##Table 1: Covariate balance results
##################

rd.export3(list(cct.mayor_lagged2,
            cct.mayor_lagged4,
              cct.demshare_lagged2,
              cct.demshare_lagged4,
               cct.exp_delta2_lagged,cct.exp_delta2_lagged2))


##################
## Table 2: Expenditure results
##################

## Main results on different expenditure categories. Results in per capita amounts.
rd.export4(list(cct.expenditures,
               cct.expenditures.general,
                cct.highways,
               cct.parks,
               cct.housing,
               cct.libraries,
               cct.education,
               cct.fire,
               cct.police,
               cct.health,
               cct.sanitation,
               cct.utilities,
                cct.welfare,
               cct.admin,
               cct.interest
              ))

## Results in logged per capita amounts.
rd.export4(list(cct.expenditures.log,
               cct.expenditures.general.log,
               cct.highways.log,
               cct.parks.log,
               cct.housing.log,
               cct.libraries.log,
               cct.education.log,
               cct.fire.log,
               cct.police.log,
               cct.health.log,
               cct.sanitation.log,
               cct.utilities.log,
               cct.welfare.log,
               cct.admin.log,
       			cct.interest.log
               ))

##################
##Table 3: Revenue results
##################

## Main results on different revenue categories. Results in per capita amounts.
rd.export4(list(cct.revenue, 
	cct.revenueown,
              cct.taxes ,
                cct.propertytaxPC,
                cct.salestaxPC,
               cct.revenueig,
			cct.debt))

## Results in logged per capita amounts.
rd.export4(list(cct.revenue.log,
                  cct.revenueown.log,
          cct.taxes.log,
                cct.propertytaxPC.log,
                cct.salestaxPC.log,
               cct.revenueig.log,
               cct.debt.log))






 ##################
## Robustness checks
 ##################
 
 ## Table 4: Comparing results using different data sources
    rd.export4(list(cct.expenditures,cct.expenditures.fg,
              cct.expenditures.gh,
 cct.expenditures.oc
              ))
              
 ## Table 5: Comparing results using medium and large cities
     rd.export4(list(cct.expenditures,cct.expenditures.medium,
              cct.expenditures.large
              ))                

(Z_size = (cct.expenditures.large$coef[1,1] - cct.expenditures.medium$coef[1,1])/sqrt(cct.expenditures.large$se[3,1]^2 + cct.expenditures.medium$se[3,1]^2))
SE_size<-sqrt(cct.expenditures.large$se[1,1]^2 + cct.expenditures.medium$se[1,1]^2)
Pvalue_size<-2*pnorm(-abs(Z_size))



### Table 6: Over-time heterogeneity results
rd.export4(list(cct.expenditures,cct.expenditures1,
cct.expenditures2,cct.expenditures3))

(Z_time = (cct.expenditures1$coef[1,1] - cct.expenditures2$coef[1,1])/sqrt(cct.expenditures1$se[3,1]^2 + cct.expenditures2$se[3,1]^2))
SE_time<-sqrt(cct.expenditures1$se[1,1]^2 + cct.expenditures2$se[1,1]^2)
Pvalue_time<-2*pnorm(-abs(Z_time))

(Z_time2 = (cct.expenditures1$coef[1,1] - cct.expenditures3$coef[1,1])/sqrt(cct.expenditures1$se[3,1]^2 + cct.expenditures3$se[3,1]^2))
SE_time2<-sqrt(cct.expenditures1$se[1,1]^2 + cct.expenditures3$se[1,1]^2)
Pvalue_time2<-2*pnorm(-abs(Z_time2))

 ## Table 7: Comparing results using south and non-south

rd.export4(list(cct.expenditures,cct.expenditures.nonsouth,cct.expenditures.south
               ))

(Z_region = (cct.expenditures.south$coef[1,1] - cct.expenditures.nonsouth$coef[1,1])/sqrt(cct.expenditures.south$se[3,1]^2 + cct.expenditures.nonsouth$se[3,1]^2))
SE_region<-sqrt(cct.expenditures.south$se[1,1]^2 + cct.expenditures.nonsouth$se[1,1]^2)
Pvalue_region<-2*pnorm(-abs(Z_region))



##################
### Institutional Results
##################

## Table 8: Partisan elections
rd.export4(list(cct.expenditures_p,
              cct.expenditures_np

              ))
 (Z_partisan_elections = (cct.expenditures_p$coef[1,1] - cct.expenditures_np$coef[1,1])/sqrt(cct.expenditures_p$se[3,1]^2 + cct.expenditures_np$se[3,1]^2))
SE_partisan<-sqrt(cct.expenditures_p$se[1,1]^2 + cct.expenditures_np$se[1,1]^2)
Pvalue_partisan<-2*pnorm(-abs(Z_partisan_elections))             
              
              
  ##  Table 9: council-manager vs strong mayor cities
rd.export4(list(cct.expenditures_manager,
              cct.expenditures_nomanager

              ))
 
 
(Z_manager = (cct.expenditures_manager$coef[1,1] - cct.expenditures_nomanager$coef[1,1])/sqrt(cct.expenditures_manager$se[3,1]^2 + cct.expenditures_nomanager$se[3,1]^2))
SE_manager<-sqrt(cct.expenditures_manager$se[3,1]^2 + cct.expenditures_nomanager$se[3,1]^2)
Pvalue_manager<-2*pnorm(-abs(Z_manager))

                             

##########################
### Appendix C, sensitivity to different bandwidths
########################
## unlogged expenditures per capita

cct.expenditures <- with(data2, rdrobust(y=Total.Expenditure.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

data2$mayor_party_final2[data2$mayor_party_final=="D"]<-1
data2$mayor_party_final2[data2$mayor_party_final=="R"]<-0
data2$bandwidth<-abs(data2$demshare-0)

expenditures_bandwidths<-matrix(nrow=50, ncol=3)
colnames(expenditures_bandwidths)<-c("bandwidth", "coef", "se")
expenditures_bandwidths<-as.data.frame(expenditures_bandwidths)

bandwidth<-c(seq(.01,.09,.01),0.1047533,seq(.11,.5,.01))
for(i in 1:50){
	reg<-with(data2[data2$bandwidth<bandwidth[i],], lm(Total.Expenditure.D2~demshare+demshare*mayor_party_final2))
	expenditures_bandwidths$coef[i]<-coef(reg)[3]
	expenditures_bandwidths$se[i]<-coef(summary(reg))[3,2]
}
expenditures_bandwidths$bandwidth<-as.numeric(seq(1,50,1))

expenditures_bandwidths$color<-'red'
expenditures_bandwidths$color[10]<-'blue'

#expenditures_bandwidths <- transform(expenditures_bandwidths, bandwidth=reorder(bandwidth, order) ) 

title<-paste("Effect of Mayoral Partisanship on Municipal Expenditures Per Capita \n", "Sensitivity of Results to Different Bandwidths \n", sep="")

pdf(paste("expenditures_bandwidths",".pdf",sep="")) # for paper
ggplot(data = expenditures_bandwidths, aes(y = coef, x = bandwidth)) +
   geom_point( colour = expenditures_bandwidths$color, size = 3)+
geom_errorbar(aes(x = bandwidth, 
                    ymin = coef - 1.96*se, ymax = coef + 1.96*se, height=.1),
                    colour = expenditures_bandwidths$color)+ xlab("Bandwidth")+ ylab("Effect on Municipal Expenditures Per Capita")+
                     geom_vline(xintercept = 0,size=.5,colour="blue",linetype="dotted") + theme(axis.text.y = element_text(angle = 0, hjust = 0, color="black")) +  
     ggtitle(title)+
     theme_bw() +
     theme(plot.title = element_text(lineheight=.8, face="bold"))
dev.off()

## logged expenditures per capita

cct.expenditures.log <- with(data2, rdrobust(y=Total.Expenditure.D2.log , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

data2$mayor_party_final2[data2$mayor_party_final=="D"]<-1
data2$mayor_party_final2[data2$mayor_party_final=="R"]<-0
data2$bandwidth<-abs(data2$demshare-0)

expenditures_bandwidths<-matrix(nrow=50, ncol=3)
colnames(expenditures_bandwidths)<-c("bandwidth", "coef", "se")
expenditures_bandwidths<-as.data.frame(expenditures_bandwidths)

bandwidth<-c(seq(.01,.09,.01),0.1035,seq(.11,.5,.01))
for(i in 1:50){
	reg<-with(data2[data2$bandwidth<bandwidth[i],], lm(Total.Expenditure.D2.log~demshare+demshare*mayor_party_final2))
	expenditures_bandwidths$coef[i]<-coef(reg)[3]
	expenditures_bandwidths$se[i]<-coef(summary(reg))[3,2]
}
expenditures_bandwidths$bandwidth<-as.numeric(seq(1,50,1))

expenditures_bandwidths$color<-'red'
expenditures_bandwidths$color[10]<-'blue'

#expenditures_bandwidths <- transform(expenditures_bandwidths, bandwidth=reorder(bandwidth, order) ) 

title<-paste("Effect of Mayoral Partisanship on Log Municipal Expend. Per Capita \n", " Sensitivity of Results to Different Bandwidths \n", sep="")

pdf(paste("expenditures_bandwidths_log",".pdf",sep="")) # for paper
ggplot(data = expenditures_bandwidths, aes(y = coef, x = bandwidth)) +
   geom_point( colour = expenditures_bandwidths$color, size = 3)+
geom_errorbar(aes(x = bandwidth, 
                    ymin = coef - 1.96*se, ymax = coef + 1.96*se, height=.1),
                    colour = expenditures_bandwidths$color)+ xlab("Bandwidth")+ ylab("Effect on Logged Municipal Expenditures Per Capita")+
                     geom_vline(xintercept = 0,size=.5,colour="blue",linetype="dotted") + theme(axis.text.y = element_text(angle = 0, hjust = 0, color="black")) +  
     ggtitle(title)+
     theme_bw() +
     theme(plot.title = element_text(lineheight=.8, face="bold"))
dev.off()


############
#### Appendix E
############


## 1. Focus on spending amounts rather than shares

cor.spending<-rep(NA, 13)
cor.spending[1]<-cor(data2$highways.PC.D2, data2$highways.perc.D2, use="complete.obs")
cor.spending[2]<-cor(data2$parks.PC.D2, data2$parks.perc.D2, use="complete.obs")
cor.spending[3]<-cor(data2$housing.PC.D2, data2$housing.perc.D2, use="complete.obs")
cor.spending[4]<-cor(data2$libraries.PC.D2, data2$libraries.perc.D2, use="complete.obs")
cor.spending[5]<-cor(data2$education.PC.D2, data2$education.perc.D2, use="complete.obs")
cor.spending[6]<-cor(data2$fire.PC.D2, data2$fire.perc.D2, use="complete.obs")
cor.spending[7]<-cor(data2$police.PC.D2, data2$police.perc.D2, use="complete.obs")
cor.spending[8]<-cor(data2$health.PC.D2, data2$health.perc.D2, use="complete.obs")
cor.spending[9]<-cor(data2$sanitation.PC.D2, data2$sanitation.perc.D2, use="complete.obs")
cor.spending[10]<-cor(data2$utilities.PC.D2, data2$utilities.perc.D2, use="complete.obs")
cor.spending[11]<-cor(data2$welfare.PC.D2, data2$welfare.perc.D2, use="complete.obs")
cor.spending[12]<-cor(data2$admin.PC.D2, data2$admin.perc.D2, use="complete.obs")
cor.spending[13]<-cor(data2$interest.PC.D2, data2$interest.perc.D2, use="complete.obs")
mean(cor.spending)

cct.education.shares <- with(data2, rdrobust(y=education.perc.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.fire.shares <- with(data2, rdrobust(y=fire.perc.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.police.shares <- with(data2, rdrobust(y=police.perc.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.health.shares <- with(data2, rdrobust(y=health.perc.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.highways.shares <- with(data2, rdrobust(y=highways.perc.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.housing.shares <- with(data2, rdrobust(y=housing.perc.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.libraries.shares <- with(data2, rdrobust(y=libraries.perc.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.parks.shares <- with(data2, rdrobust(y=parks.perc.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.sanitation.shares <- with(data2, rdrobust(y=sanitation.perc.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.utilities.shares <- with(data2, rdrobust(y=utilities.perc.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.welfare.shares <- with(data2, rdrobust(y=welfare.perc.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.interest.shares <- with(data2, rdrobust(y=interest.perc.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

cct.admin.shares <- with(data2, rdrobust(y=admin.perc.D2 , x=demshare ,
                                     bwselect="CCT", all=TRUE, kernel='uni'))

rd.export.shares(list(
                cct.highways.shares,
               cct.parks.shares,
               cct.housing.shares,
               cct.libraries.shares,
               cct.education.shares,
               cct.fire.shares,
               cct.police.shares,
               cct.health.shares,
               cct.sanitation.shares,
               cct.utilities.shares,
                cct.welfare.shares,
               cct.admin.shares,
               cct.interest.shares
              ))

